/*  
  -- The Lime II Project -- 

  A tuplespaces-based middleware for coordinating agents and mobile hosts.
  Copyright (C) 2005.
  Gian Pietro Picco, Amy L. Murphy, Lorenzo Bellini.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received this copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */

package lime2.ca;

import lime2.*;
import java.io.Serializable;

/**
 * Models a message of dis/engagement.
 * 
 * @author Gian Pietro Picco
 * @author Amy Murphy
 * @author Lorenzo Bellini
 */

public class EngMsg implements Serializable {

	private static final long serialVersionUID = 5720509673585725138L;

	/** Serialized HELLO message. */
	public final static byte[] HELLO = Serializer.serialize(new EngMsg(
			LimeConstants.HELLO, Location.HERE.getID()));

	/** Serialized BYE message. */
	public final static byte[] BYE = Serializer.serialize(new EngMsg(
			LimeConstants.BYE, Location.HERE.getID()));

	/** Type of message. */
	public byte type;

	/** Source host of the engagement message. */
	public LimeServerID source;

	/** record the send time */
	public long sendHelloTime;

	/**
	 * Constructor method (private).
	 * 
	 * @param type
	 *            type of the engagement message
	 * @param source
	 *            source host of the engagement message
	 */
	private EngMsg(byte type, LimeServerID source) {
		this.type = type;
		this.source = source;
	}

	private EngMsg(byte type, LimeServerID source, long sendHelloTime) {
		this.type = type;
		this.source = source;
		this.sendHelloTime = sendHelloTime;
	}

	/**
	 * Generate a HELLO message with send time stamp
	 * @param timestamp
	 * @return the serialized fomr of RICHHELLO
	 * @author Xing Jiankuan
	 */
	public static byte[] createRichHello(long timestamp) {
		return Serializer.serialize(new EngMsg(LimeConstants.HELLO,
				Location.HERE.getID(), timestamp));
	}
}
